#include "Thread.hpp"
#include "BlockQueue.hpp"
#include <iostream>
#include <vector>

using namespace ThreadModule;

void ProducerDone(BlockQueue<int>& bq, int count_until)
{
    int cnt = 1;
    while(cnt < count_until)
    {
        bq.push(cnt);
        std::cout << "Producer push: " << cnt << std::endl;
        cnt++;
        sleep(2);
    }
}

void ConsumerDone(BlockQueue<int>& bq)
{
    int get_count = 0;
    while(true)
    {
        bq.pop(&get_count);
        std::cout << "Consumer get count: " << get_count << std::endl;
        sleep(1);
    }
}

void test()
{
    int count_until = 100;
    BlockQueue<int> bq;
    Thread("Consumer", ConsumerDone, std::ref(bq));
    Thread("Producer", ProducerDone, std::ref(bq), count_until);

    sleep(100);     // wait for two thread
}


int main()
{
    test();
    
    return 0;
}
